package fudan.se.project.controller.request;

import fudan.se.project.domain.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.*;

/**
 * @author X Yang
 * property need to be inspected
 */
@Data
@AllArgsConstructor
@NoArgsConstructor

public class RegisterRequest {

    @Size(min = 5, max = 32)
    @Pattern(regexp = "(?i)^([a-z]|-)+([a-z]|[0-9]|-|_)*$")
    private String username;

    @Pattern(regexp = "^(?![\\d]+$)(?![a-zA-Z]+$)(?![-_]+$)[\\da-zA-Z-_]{6,32}$")
    private String password;

    @Email
    private String email;

    @NotNull
    @NotBlank
    private String organization;
    @NotNull
    @NotBlank
    private String region;
    @NotNull
    @NotBlank
    private String realname;

    public User toUser() {
        return new User(username, realname, password, email, organization, region);
    }

}

